#!/bin/sh
# PCP QA Test No. 1367
# dbpmda for simple pmda labels, verifying python and C PMDAs produce output
#
# Copyright (c) 2017 Red Hat.  All Rights Reserved.
#
seq=`basename $0`
echo "QA output created by $seq"

. ./common.python

[ -d $PCP_PMDAS_DIR/simple ] || _notrun "simple PMDA directory is not installed"
$python -c "from pcp import pmda" >/dev/null 2>&1
[ $? -eq 0 ] || _notrun "python pcp pmda module not installed"
test -f "$PCP_PMDAS_DIR/simple/pmdasimple.python"
[ $? -eq 0 ] || _notrun "python simple pmda not yet installed"

python_path=`which $python`
trap "rm -f $tmp.*; exit" 0 1 2 3 15

_filter()
{
    sed \
	-e "s;$PCP_PMDAS_DIR;\$PCP_PMDAS_DIR;" \
	-e "s;$python_path;\$PCP_PYTHON_PROG;" \
	-e "s;$python_basename;python;" \
	-e "/^Start/d" \
    | _filter_dumpresult
}

domain=253

# ensure help text exists
cd "$PCP_PMDAS_DIR/simple"
$sudo ./Install </dev/null >/dev/null 2>&1

$sudo TERM=ansi dbpmda -n root <<End-of-File 2>&1 | _filter > $tmp.simple.python
open pipe $python_path pmdasimple.python
label domain
label indom $domain.0
label indom $domain.1
label cluster $domain.0
label cluster $domain.1
label cluster $domain.2
label item $domain.2.4
End-of-File

$sudo TERM=ansi dbpmda -n root <<End-of-File 2>&1 | _filter > $tmp.simple.C
open pipe pmdasimple -d $domain
label domain
label indom $domain.0
label indom $domain.1
label cluster $domain.0
label cluster $domain.1
label cluster $domain.2
label item $domain.2.4
End-of-File

echo diff between C and python labels output, EXPECT NO OUTPUT
diff $tmp.simple.python $tmp.simple.C

echo "--- C ---" >>$seq_full
cat $tmp.simple.C >>$seq_full
echo "--- python ---" >>$seq_full
cat $tmp.simple.python >>$seq_full

status=0
exit
